﻿Imports System.Data.SqlClient

Public Class AdminWaitListBorrow
    Inherits System.Web.UI.Page
    Dim mt As New MuonTra_BLL()
    Dim mtc As New MuonTra_DTO()
    Dim objUser As New LoginHelper("", "")
    Dim flag As Boolean = False
    Dim id_sach As String
    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        loadDSChoMuon()
    End Sub
    Public Sub loadDSChoMuon()
        grid_dschomuon.DataSource = mt.loadDSChoMuon()
        grid_dschomuon.DataBind()

    End Sub

    Protected Sub grid_dschomuon_CustomColumnDisplayText(ByVal sender As Object, ByVal e As DevExpress.Web.ASPxGridViewColumnDisplayTextEventArgs) Handles grid_dschomuon.CustomColumnDisplayText
        If e.Column.FieldName = "kieumuon" Then
            If CBool(e.Value) Then
                e.DisplayText = "Mượn Về Nhà"
            Else
                e.DisplayText = "Mượn Tại Chỗ"
            End If
        End If
    End Sub

    Protected Sub grid_dschomuon_RowDeleting(ByVal sender As Object, ByVal e As DevExpress.Web.Data.ASPxDataDeletingEventArgs) Handles grid_dschomuon.RowDeleting
        mtc._idsach = e.Values("id_sach")
        mtc._taikhoan = e.Values("taikhoan")
        mt.xoaDSChoMuon(mtc)
        e.Cancel = True
        loadDSChoMuon()
    End Sub

    Protected Sub grid_dschomuon_CustomButtonCallback(ByVal sender As Object, ByVal e As DevExpress.Web.ASPxGridViewCustomButtonCallbackEventArgs) Handles grid_dschomuon.CustomButtonCallback
        If e.ButtonID = "bt_chuyenmuon" Then
            Try
                objUser = TryCast(Session("sesLoginAdmin"), LoginHelper)
                mtc._idsach = grid_dschomuon.GetRowValues(e.VisibleIndex, "id_sach")
                mtc._taikhoan = grid_dschomuon.GetRowValues(e.VisibleIndex, "taikhoan")
                mtc._kieumuon = grid_dschomuon.GetRowValues(e.VisibleIndex, "kieumuon")
                mtc._ngaymuon = grid_dschomuon.GetRowValues(e.VisibleIndex, "ngaymuon")
                mtc._ngaytra = grid_dschomuon.GetRowValues(e.VisibleIndex, "ngaytra")
                mtc._tennvmuon = objUser.UserName
                mt.themMuonTuDSCho(mtc)
                flag = False
                loadDSChoMuon()
            Catch ex As SqlException
                id_sach = grid_dschomuon.GetRowValues(e.VisibleIndex, "id_sach")
                flag = True
                grid_dschomuon.JSProperties("cp_showAlertMessage") = ex.Message
            End Try
        End If

    End Sub

    Protected Sub grid_dschomuon_HtmlDataCellPrepared(ByVal sender As Object, ByVal e As DevExpress.Web.ASPxGridViewTableDataCellEventArgs) Handles grid_dschomuon.HtmlDataCellPrepared
        If e.DataColumn.FieldName = "id_sach" Then
            If flag = True And e.CellValue = id_sach Then
                e.Cell.ForeColor = Drawing.Color.DarkRed
                e.Cell.Font.Bold = True
                e.Cell.ToolTip = "Sách Đã Có Người Mượn"
            End If
        End If
    End Sub
End Class